package com.ykw.parking.service;

import com.ykw.parking.mapper.UserMapper;
import com.ykw.parking.pojo1.UserLoan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Author: tang
 * @Date: 2021/08/31/21:02
 * @Description: 定时任务
 */
@Service
public class ScheduledService {
    @Autowired
    UserMapper userMapper;
    @Scheduled(cron = "0 0 22 * * ?")
    public void hello(){

        List<UserLoan> allLoan = userMapper.getAllLoan();
        for (UserLoan userLoan : allLoan) {
            Date date = userLoan.getDate();
            Date date1 = new Date(System.currentTimeMillis());
            if(date.before(date1)){
                userMapper.updLoanI((userLoan.getInterest()+userLoan.getMoney())*0.0005,userLoan.getId());
            }
        }
    }
}
